package com.infinitus.activity.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.aliyun.opensearch.sdk.dependencies.com.google.common.collect.Lists;
import com.infinitus.activity.pojo.DO.AuldrawWinnerDo;
import com.infinitus.activity.util.FxhClient;
import com.infinitus.activity.util.KeyGenerator;
import com.infinitus.activity.util.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
/**
 * @create: 2019/1/9
 * @desc:
 */
@Service
public class PushListService {

    private static Logger logger = Logger.getLogger(PushListService.class);
    @Resource
    RedisTemplate<String, AuldrawWinnerDo> redisTemplate;
    @Autowired
    FxhClient fxhClient;

    @Value("${activity-code}")
    private String activityCode;

    @Value("${deploycolId}")
    private String deploycolId;

    @Transactional(rollbackFor = Exception.class)
    public void sendWinningDataToDB() {


            /*List<AuldrawWinnerDo> auldrawWinnerDoList = Lists.newArrayList();

            for(int i=0; i < 100; i++) {

                //AuldrawWinnerDo auldrawWinnerDo = redisTemplate.opsForList().rightPop(key); //清除redis中中奖纪录
                if(null != auldrawWinnerDo){
                    if (!"8080".equals(auldrawWinnerDo.getAwardsId())) {

                        String amount = getRewardById(auldrawWinnerDo.getAwardsId());
                        logger.error("中奖记录：工号----" + auldrawWinnerDo.getDealerNo() + "奖品---" + auldrawWinnerDo.getAwardsId());*/

//                        AddPointsVO addPointsVO = new AddPointsVO();
//                        addPointsVO.setCardNo(auldrawWinnerDo.getDealerNo());
//                        addPointsVO.setPointValue(amount);
//
//                        // 测试用的日期
//                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                        addPointsVO.setInteractivateDate(sdf.parse("2019-01-04 10:24:29"));
//
//                        addPointsVO.setInteractivateDate(new Date());
//                        String porcCode = fxhClient.addPoints(addPointsVO);
//                        if (!StringUtils.isEmpty(porcCode)) {
//                            auldrawWinnerDo.setPorcCode(porcCode);
//                        }

            //auldrawWinnerDo.setPorcCode("");
              /*
                    auldrawWinnerDoList.add(auldrawWinnerDo);
                }else{
                    break;
                }*/
/*
            if (!auldrawWinnerDoList.isEmpty()) {
                // 生成中奖记录
                //auldrawWinnerMapper.batchInsert(auldrawWinnerDoList);
            } else {
                logger.error("没有可以插入中奖记录");
            }
        } catch (Exception e) {
            logger.error(e);
        }*/


   /* private String getRewardById(String id) {
        if (StringUtils.isEmpty(id)) {
            return "0";
        }
        switch (id) {
            case "1000":
                return "5000";
            case "1001":
                return "1000";
            case "1002":
                return "500";
            case "1003":
                return "200";
            case "1004":
                return "100";
            case "1005":
                return "50";
            default:
                return "0";

        }
*/
    }
}